package org.jfedor.frozenbubble;

import java.io.File;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.widget.ImageView; 
import android.widget.Button;
import android.widget.LinearLayout;

public class OptionsActivity extends Activity {

	public boolean musicOn = true;
	public boolean soundOn = true;
	public boolean fileExist = true; // check to see if file exist some how
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_options);

        //Floating Animation
        Animation floatingM = AnimationUtils.loadAnimation(this, R.anim.floating);
        Animation floatingS = AnimationUtils.loadAnimation(this, R.anim.floating);
        Animation floatingD = AnimationUtils.loadAnimation(this, R.anim.floating);
        
        //Music Button        
        final Button music = (Button)findViewById(R.id.musicButton);
        music.startAnimation(floatingM);
        
        music.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {            
            	
            	if(musicOn){
            		musicOn = false;
            		
            		music.setBackgroundResource(R.drawable.music_off);
            	}
            	else{
            		musicOn = true;
            		music.setBackgroundResource(R.drawable.music_on);
            	}
           
            }
        });
        
        //Sound Button        
        final Button sound = (Button)findViewById(R.id.soundButton);
        floatingS.setStartOffset(200);
        sound.startAnimation(floatingS);
        
        sound.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {            
            	
            	if(soundOn){
            		soundOn=false;
            		//FrozenBubble.setSoundOn(false);
            		sound.setBackgroundResource(R.drawable.sound_off);
            	}
            	else{
            		soundOn = true;
            		//FrozenBubble.setSoundOn(true);
            		sound.setBackgroundResource(R.drawable.sound_on);
            	}
           
            }
        });
        
        //Delete Button        
        final Button delete = (Button)findViewById(R.id.deleteButton);
        floatingD.setStartOffset(400);
        delete.startAnimation(floatingD);
        File file = getFileStreamPath("calibration.txt");
        
        if(file.exists()){
        	fileExist = true;
        	delete.setBackgroundResource(R.drawable.delete);
        }
        else {
        	fileExist = false;
        	delete.setBackgroundResource(R.drawable.delete2);
        }
        
        delete.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
            	
            	if(fileExist){
            		fileExist = false;
            		
            		delete.setBackgroundResource(R.drawable.delete2);  
            		
            		// Delete previous calibration file
            		deleteFile("calibration.txt");
            	}

           
            }
        });
    }
    
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        if ((keyCode == KeyEvent.KEYCODE_BACK))
        {
        	finish();
        	
        	//Attempting to go back to the Title Screen
			Intent title_intent = new Intent(OptionsActivity.this, ChillOut.class);
			startActivity(title_intent);

        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    public void onBackPressed() {
    }

}
